<?php namespace Admin\Controller;
/*
 * 友情链接控制器
 * */	
 	class LinkController extends CommonController
 	{
 		protected $db;
		/*
		 * 构造方法
		 * */
		public function __init(){
			$this->db = new \Common\Model\Link;
		}
		/*
		 * shouye
		 * */
 		public function index()
		{
			//获得数据
			$data = $this->db->get();
			View::with("data",$data);
			View::make("link");
		}
		/*
		 *添加方法
		 * */
		 public function addlink()
		 {
		 	if(IS_POST){
			 	if(!$this->db->add_link()){
			 		View::error($this->db->getError());
			 	}else{
			 		View::success("添加成功",U("index"));
			 	}
			}
		 	View::make("addLink");
		 }
		 /*
		  * 编辑
		  * */
		 public function resetlink()
		 {
		 	//获得lid
		 	$lid =Q("get.lid",0,"intval");
		 	//获得元数据
		 	$OldData = $this->db->where("lid",$lid)->first();
			//p($OldData);die;
			View::with("OldData",$OldData);
			if(IS_POST){
				if(!$this->db->edit($lid)){
					View::error($this->db->getError());
				}else{
					View::success("编辑成功",U("index"));
				}
			}
		 	View::make();
		 }
		/*
		 * 删除
		 * */
		 public function del()
		 {
		 	//获得lid
		 	$lid =Q("get.lid",0,"intval");
			if(!$this->db->del($lid)){
				View::error("删除失败");
			}else{
				View::success("删除成功",U("index"));
			}
		 }
 	}
